<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:include href="../admin.xsl" />
	<xsl:include href="path.xsl" />
	
	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/admin/cp.css" type="text/css" media="all" />
			<script type="text/javascript">
				var cpDirId = <xsl:value-of select="response/@dir-id" />;
			</script>
		</head>
		<body>
			<xsl:call-template name="admin-header" />
			
			<div id="blocks">
				<div id="blocks_inner" />
			</div>
			
			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response">		
		<div id="path">
			<xsl:apply-templates select="document(concat('xmodule://cp/getPath/', @dir-id))/data/response" mode="cp-path" />
		</div>
		
		<div id="cp_settings_wrapper">
			<div id="cp_settings">
				<h3>Новый ярлык</h3>
				
				<div id="cp_errors" />
				
				<form action="{$baseURI}/admin/cp/js_add_item/{@dir-id}" method="post" onsubmit="cpSettingsErrorClear();" target="backframe" enctype="multipart/form-data">
					<div class="block">
						<div class="item">
							<xsl:text>Родительский раздел:</xsl:text>
							<br />
							<select name="data[new][rel_id]" id="cp_items_tree">
								<option value="0">начальный уровень</option>
							</select>
						</div>
						<div class="item">
							<xsl:text>Название:</xsl:text>
							<br />
							<input class="inp" type="text" name="data[new][title]" value="" />
						</div>
					</div>
					<div class="block">
						<div class="item">
							<xsl:text>Тип:</xsl:text>
							<br />
							<select name="data[new][type]" onchange="cpSettingsToggleLinks(this.value);">
								<option value="dir">каталог</option>
								<option value="link">ссылка</option>
							</select>
						</div>
						<div class="item">
							<xsl:text>Иконка (16×16 png):</xsl:text>
							<br />
							<div id="cp_item_icon_file">
								<input size="15" type="file" name="icon" />
								<xsl:text> </xsl:text>
								<a class="on_page" href="#" onclick="cpSettingsChangeIconField(); return false;">ввести путь</a>
							</div>
							<div id="cp_item_icon_path" style="display:none">
								<input class="inp icon" type="text" name="icon_path" value="" />
								<xsl:text> </xsl:text>
								<a class="on_page" href="#" onclick="cpSettingsChangeIconField(); return false;">загрузить</a>
							</div>
						</div>
					</div>
					<div class="block" id="block_module_links" style="display:none">
						<div class="item">
							<xsl:text>Модуль:</xsl:text>
							<br />
							<input class="inp" type="text" name="data[new][link_module]" value="" />
						</div>
						<div class="item">
							<xsl:text>Метод:</xsl:text>
							<br />
							<input class="inp" type="text" name="data[new][link_method]" value="" />
						</div>
					</div>
					<p>
						<input type="submit" value="Добавить" />
					</p>
				</form>
				
				<iframe name="backframe" style="display:none" src="about:blank" width="1" height="1"></iframe>
			</div>
			
			<div id="cp_settings_button_line">
				<a href="#" onclick="cpSettingsSlide({@dir-id}); return false;">настройки</a>
			</div>
		</div>
		
		<xsl:apply-templates select="message" />
		
		<form action="" method="post">		
			<div id="list_cp_items">
				<xsl:apply-templates select="object[@type='cp_item']" />
			</div>
			
			<p id="delete_button_wrapper">
				<input type="submit" name="delete" value="Удалить выбранные" />
			</p>
		</form>
	</xsl:template>
	
	<xsl:template match="object[@type='cp_item']">
		<xsl:param name="useDrag" />
		<xsl:param name="draggedElementPrefix" />
		
		<xsl:param name="dirId" select="property[@name='link_dir_id']/value" />
		<xsl:param name="itemModule" select="property[@name='link_module']/value" />
		<xsl:param name="itemMethod" select="property[@name='link_method']/value" />
		<xsl:param name="icon" select="property[@name='icon']/value" />
		
		<div class="item" id="drag_wrapper_{@id}">
			<span class="checkbox">
				<input type="checkbox" name="cp_items[]" value="{@id}" />
			</span>
			
			<span class="drag" id="drag_{@id}">
				<div title="Добавить в избранное" class="icon" onmousedown="cpItemDropFavorite(event, 'drag_{@id}', {@id})">
					<xsl:attribute name="style">
						<xsl:text>background-image: url("</xsl:text>
						<xsl:choose>
							<xsl:when test="$icon != ''">
								<xsl:value-of select="concat($baseURI, $icon)" />
							</xsl:when>
							<xsl:when test="$itemModule != ''">
								<xsl:value-of select="concat($baseURI, '/images/cp/file.png')" />
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="concat($baseURI, '/images/cp/folder.png')" />
							</xsl:otherwise>
						</xsl:choose>
						<xsl:text>");</xsl:text>
					</xsl:attribute>
				</div>
				
				<div class="link">
					<a>
						<xsl:attribute name="href">
							<xsl:choose>
								<xsl:when test="$itemModule != ''">
									<xsl:value-of select="concat($baseURI, '/admin/', $itemModule)" />
									
									<xsl:if test="$itemMethod != ''">
										<xsl:value-of select="concat('/', $itemMethod)" />
									</xsl:if>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="concat($baseURI, '/admin/cp/dir/', @id)" />
								</xsl:otherwise>						
							</xsl:choose>
						</xsl:attribute>
						<xsl:value-of select="property[@name='title']/value" />
					</a>
				</div>
			</span>
		</div>	
	</xsl:template>
	
</xsl:stylesheet>